package com.marchsoft.musicalstore.service;

import com.marchsoft.musicalstore.entity.SelClassAble;
import com.marchsoft.musicalstore.entity.User;
import com.marchsoft.musicalstore.repository.CourseTypeRepository;
import com.marchsoft.musicalstore.repository.SelClassAbleRepository;
import com.marchsoft.musicalstore.repository.UserRepository;
import com.marchsoft.musicalstore.util.MyUntil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service;

import javax.transaction.Transactional;
import java.security.NoSuchAlgorithmException;
import java.util.Date;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 源
 * Date: 2019-11-17
 * Time: 14:45
 */
@Service
@Transactional
public class TextSer {
    @Autowired
    MyUntil myUntil;
    @Autowired
    UserRepository userRepository;
    @Autowired
    CourseTypeRepository courseTypeRepository;
    @Autowired
    SelClassAbleRepository selClassAbleRepository;


    public User addUser() throws NoSuchAlgorithmException {
        User user = new User();
        user.setName("刘老师");
        user.setPassword(myUntil.mdString("4444444"));
        user.setBirthday(new Date());
        user.setCreateTime(new Date());
        user.setHeadImg("4444444");
        user.setIsDelete(0);
        user.setNickName("我是刘老师啊！");
        user.setPhone("15555557755");
        user.setSex(0);
        user.setType(1);//0是管理员，1是老师，2是学生
        User save = userRepository.save(user);
        return save;
//        return user;
    }
    public SelClassAble addCourse(){
        SelClassAble sca = new SelClassAble();
        sca.setCourseId(0);
        sca.setName("课程3");
        sca.setInfo("这是一个优秀的课程");
        sca.setNowPrice(55555555);
        sca.setType(0);
        sca.setBeforePrice(555555555);
        sca.setLimitPeonum(50);
        sca.setPassPeonum(0);
        sca.setCourseDate(new Date());
        sca.setCourseTime(1);
        sca.setTeacherId(7);
        sca.setClassHour(15);
        SelClassAble save = selClassAbleRepository.save(sca);
        return save;
//        Sort.Order xx = new Sort.Order(Sort.Direction.DESC,"passPeoNum");
//        Sort by = Sort.by(xx);


//        return null;


    }

}
